/**
 * @(#) CompanyCreditCardProxy.as
 *
 * @date		2009. 04. 6.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	 일비계산 Proxy - Proxy
 *
 */
package com.skt.common_hr.biztrip_sac.model
{
	import com.skt.common_hr.biztrip_sac.BizTripFacade;
	import com.skt.common_hr.biztrip_sac.model.vo.CompanyCreditCardVO;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.wcl.dataloader.*;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class CompanyCreditCardProxy extends CommonProxy
	{
		public static const NAME:String = "CompanyCreditCardProxy";

		public var usedCardList:ArrayCollection;

		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function CompanyCreditCardProxy(data:Object=null)
		{
			super(NAME, data);
		}


		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 *
		 * @param pernr 사번,대상월
		 * @return void
		 */
		public function load(cardNo:String, BEGDA:Date, ENDDA:Date, I_GUBUN:String):void
		{
			var param:Object = new Object();
			param["CARDNO"] 	= cardNo;
			param["FDATE"] 		= DateUtil.toBasicString(BEGDA);
			param["TDATE"] 		= DateUtil.toBasicString(ENDDA);
			param["I_GUBUN"] 	= I_GUBUN;			

			trace(param["CARDNO"]+","+param["FDATE"]+","+param["TDATE"]);
			loadData("ZFI_HR_CARD_DISP", param, result, fault);
		}



		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 *
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(event.result["RETCODE"]==0) {
				usedCardList = parseCardList(event.result.E_CARD);
				facade.sendNotification(BizTripFacade.LOAD_USEDCARDLIST_COMPLETE, this);
			}
			else {
				trace( "failed to 법인카드 사용내역: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				facade.sendNotification(BizTripFacade.LOAD_USEDCARDLIST_FAILED, this);
			}
		}

		/**
		 * 서버에서 오류가 발생했을 처리
		 *
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			trace("Fault message in 법인카드 사용내역: " + event.fault.faultString);
			facade.sendNotification(BizTripFacade.LOAD_USEDCARDLIST_FAILED, this);
		}





		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 *
		 * @param
		 * @return 제증명서 종류 Code list
		 */
		private function parseCardList(srcArr:ArrayCollection):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection;
			for each(var rec:Object in srcArr)
			{
				var vo:CompanyCreditCardVO = new CompanyCreditCardVO();
				vo.CARDNO	= rec["CARDNO"];
				vo.APDAT	= DateUtil.stringToDateTime(rec["APDAT"]);
				vo.APNO		= rec["APNO"];
				vo.APAMT	= rec["APAMT"];
				vo.STNAME	= rec["STNAME"];
				vo.WAERS	= rec["WAERS"];
				vo.USED_NO	= rec["USED_NO"];
				/*  // 이 펑션은 처리안함
				if(vo.WAERS=="KRW") {
					vo.APAMT *= 10;
					vo.APAMT *= 10;
				}
				*/
				list.addItem(vo);
			}
			return list;
		}

	}
}